home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / s_to_z / sysfile / sysprot.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  2.9 KB  |  109 lines

  1. {=================================================
  2.  Program: SysFile.Exe
  3.  Version: 1.0
  4.  Module: SysProt.pas
  5.  Author: Wayne Niddery
  6.  CopyRight ⌐ 1995 Wayne Niddery and WinWright
  7.  =================================================}
  8. unit Sysprot;
  9.  
  10. {SysProt is a very simple dialog with a TMemo that allows direct
  11.  editing by the user to add or remove file names. The purpose is
  12.  to protect against accidental deletion of files. This is needed as
  13.  it's very easy to delete files using the popup menus.}
  14.  
  15. interface
  16.  
  17. uses
  18.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  19.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, IniFiles;
  20.  
  21. type
  22.   TProtectDlg = class(TForm)
  23.     Panel1: TPanel;
  24.     ProtList: TMemo;
  25.     Label1: TLabel;
  26.     ProtOK: TBitBtn;
  27.     ProtCancel: TBitBtn;
  28.     procedure FormCreate(Sender: TObject);
  29.     procedure FormDestroy(Sender: TObject);
  30.     procedure ProtCancelClick(Sender: TObject);
  31.     procedure ProtListKeyPress(Sender: TObject; var Key: Char);
  32.   private
  33.     { Private declarations }
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. var
  39.   ProtectDlg: TProtectDlg;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. uses
  46.   SysGlb;
  47.  
  48. {called when ProtectDlg first created}
  49. procedure TProtectDlg.FormCreate(Sender: TObject);
  50. var
  51.   i: integer;
  52.   s: string;
  53. begin
  54.   if not FileExists(SysIni.FileName) then
  55.     {first time run on this system, so use default list of files}
  56.     for i := 0 to High(DefProt) do
  57.       ProtList.Lines.Add(Defprot[i])
  58.   else begin {read protection list from INI file}
  59.     i := 0;
  60.     repeat
  61.       {the keys to each file name are numbers beginning with 0}
  62.       s := SysIni.ReadString(iniProtect, IntToStr(i), '');
  63.       if Length(s) > 0 then ProtList.Lines.Add(s);
  64.       inc(i);
  65.     until Length(s) = 0;
  66.     ProtList.Modified := False; {user hasn't changed list yet}
  67.   end;
  68. end;
  69.  
  70. {called when program shuts down}
  71. procedure TProtectDlg.FormDestroy(Sender: TObject);
  72. var
  73.   i: integer;
  74. begin
  75.   {remove old list of names from protect section of INI}
  76.   SysIni.EraseSection(iniProtect);
  77.   {add current list back to INI}
  78.   for i := 0 to ProtList.Lines.Count - 1 do
  79.     SysIni.WriteString(iniProtect, IntToStr(i), ProtList.Lines[i]);
  80. end;
  81.  
  82. {Cancel button clicked}
  83. procedure TProtectDlg.ProtCancelClick(Sender: TObject);
  84. var
  85.   i: integer;
  86.   s: string;
  87. begin
  88.   {if any changes made to TMemo, then we need to reread file names
  89.    from INI file in order to 'erase' changes}
  90.   if ProtList.Modified then begin
  91.     i := 0;
  92.     ProtList.Lines.Clear;  {remove all lines from TMemo}
  93.     repeat
  94.       s := SysIni.ReadString(iniProtect, IntToStr(i), '');
  95.       if Length(s) > 0 then ProtList.Lines.Add(s);
  96.       inc(i);
  97.     until Length(s) = 0;
  98.     ProtList.Modified := False;
  99.   end;
  100. end;
  101.  
  102. {This handles the OnKeyPress event and allows us to force uupercase}
  103. procedure TProtectDlg.ProtListKeyPress(Sender: TObject; var Key: Char);
  104. begin
  105.   Key := UpCase(Key);
  106. end;
  107.  
  108. end.
  109.